/*
 This file is part of BTStracker
		
    BTStracker is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    BTStracker is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.	
	author: azbest.pro (azbest.pro@gmail.com)
*/
package pl.vdl.azbest.mremote.gui.composite;

import java.util.logging.Logger;

import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Group;

import pl.vdl.azbest.annotations.InProgress;
import pl.vdl.azbest.annotations.Level;
import pl.vdl.azbest.annotations.TODO;
import pl.vdl.azbest.annotations.Team;
import pl.vdl.azbest.log.LoggingTheGathering;
import pl.vdl.azbest.mremote.Conf;
import pl.vdl.azbest.mremote.com.CommObserver;

import pl.vdl.azbest.mremote.com.TextOutputStream;
import pl.vdl.azbest.mremote.gui.GUIFacade;
import pl.vdl.azbest.mremote.gui.SWTElement;


//<strike></strike>
@InProgress
@TODO(
		dateAssigned="21-03-2008",
		level=Level.IMPORTANT,
		target="<br>" +
				"<strike>1. GUI for user logging and communication </strike><br>" +
				"",
		done="1", responsible=Team.AZBEST
)
public class CompositeConsole extends Composite{

	private Group group = null;
	private Text textArea = null;
	{
		LoggingTheGathering.addPath(getClass().getName());

	}
	public CompositeConsole(Composite parent, int style) {
		super(parent, style);
		initialize();
		init();
	}

	private void initialize() {
		createGroup();
		setSize(new Point(300, 200));
		setLayout(new GridLayout());

	}


	/**
	 * This method initializes group
	 *
	 */
	private void createGroup() {
		GridData gridData1 = new GridData();
		gridData1.horizontalAlignment = GridData.FILL;
		gridData1.grabExcessHorizontalSpace = true;
		gridData1.grabExcessVerticalSpace = true;
		gridData1.verticalAlignment = GridData.FILL;
		GridData gridData = new GridData();
		gridData.horizontalAlignment = GridData.FILL;
		gridData.grabExcessHorizontalSpace = true;
		gridData.grabExcessVerticalSpace = true;
		gridData.verticalAlignment = GridData.FILL;
		group = new Group(this, SWT.NONE);
		group.setLayout(new GridLayout());
		group.setLayoutData(gridData);
		//group.setText(Conf.lang.getProperty("SystemConsole.group"));
		group.setText("Console");
		textArea = new Text(group, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
		textArea.setEditable(false);
		textArea.setLayoutData(gridData1);
		textArea.addDisposeListener(new org.eclipse.swt.events.DisposeListener() {
			public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
				GUIFacade.getInstance().removeComposite(CompositeConsole.this);
			}
		});
	}
	public void toConsole(String txt){
		this.textArea.append(txt+Conf.getInstance().LineS);
	}
	private SWTElementInner  swtEi = null;
	class SWTElementInner extends SWTElement{
		SWTElementInner(Shell s){
			this.sShell=s;
		}
		@Override
		protected void createSShell(){}
	}
	private void init(){
		GUIFacade.getInstance().addComposite(this);
	}
	public TextOutputStream getTextOutputStream(){
		return new TextOutputStream(this.textArea,getDisplay());
	}

}
